<template>
  <div>
    <div class="mymessage_1">
      <p>我的消息</p>
      <div class="mymessage_2">
        <el-main
          class="mymessage_3"
          v-for="(obj, index) in list.slice(
            (currentPage - 1) * pageSize,
            currentPage * pageSize
          )"
          :key="index"
        >
          <MyMessage
            :userName="obj.userName"
            :currentTime="obj.currentTime"
            :operation="obj.operation"
          />
        </el-main>
        <div class="mymessage_4">
          <el-pagination
            align="center"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[1, 5, 10, 20]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="list.length"
            class="ttp"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import MyMessage from "./MyMessage.vue";
export default {
  data() {
    return {
      list: [],
      currentPage: 1, // 当前页码
      pageSize: 5, // 每页的数据条数[]
      isif: -1,
      isShow: false,
    };
  },
  methods: {
    getRedisList() {
      axios({
        url: "/api/user/getRedisList",
      }).then((res) => {
        console.log(res.data);
        this.list = res.data;
      });
    },
    //每页条数改变时触发 选择一页显示多少行
    handleSizeChange(val) {
      //   alert(`每页 ${val} 条`);
      this.currentPage = 1;
      this.pageSize = val;
    },
    //当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
  },
  created() {
    this.getRedisList();
  },
  components: {
    MyMessage,
  },
};
</script>

<style lang="less" scoped>
/deep/.el-pagination__total{
  
}
.ttp{
  margin-left: 200px;
}
.mymessage_3:hover{
  background-color: #f6f6f6;
}
.mymessage_4{
  float: left;
  margin-top: 20px;
}
.mymessage_3 {
  width: 96%;
  float: left;
  margin-left: 2%;
  background-color: white;
  /* height: 60px; */
  /* margin-top: 5px; */
}
.mymessage_2 span:nth-child(1) {
  margin-top: 20px;
  float: left;
  margin-left: 30px;
  font-size: 100%;
  margin-bottom: 20px;
  color: rgb(85, 76, 76);
}
.mymessage_2 span:nth-child(3) {
  margin-top: 20px;
  float: left;
  margin-left: 250px;
  font-size: 100%;
  color: red;
}
.mymessage_2 span:nth-child(2) {
  margin-top: 23px;
  float: left;
  color: #beb5b5;
  margin-left: 50px;
}
.mymessage_2 {
  width: 96%;
  float: left;
  margin-left: 2%;
  /* margin-top: 30px; */
  /* background-color: red; */
  /* height: 1000px; */
  border-top: 1px solid #beb5b5;
}
.mymessage_1 p:nth-child(1) {
  font-size: 120%;
  margin-left: 30px;
  margin-top: 30px;
  font-weight: bold;
  margin-bottom: 30px;
  float: left;
}
.mymessage_1 {
  width: 100%;
  float: left;
}
</style>